package implementation;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Traitement {

	private List<Condition> conditions;

	public Traitement() {
		conditions = new ArrayList<Condition>();
	}

	public Traitement(NodeList conds) {
		setConditions(conds);
	}

	public Traitement(Node traitement) {
		setConditions(traitement);
	}

	public List<Condition> getConditions() {
		return conditions;
	}

	public void setConditions(List<Condition> conditions) {
		this.conditions = conditions;
	}

	public void setConditions(NodeList conds) {
		List<Condition> inter = new ArrayList<Condition>();
		for (int i = 0; i < conds.getLength(); i++) {
			inter.add(conditionNodeToObject(conds.item(i)));
		}

		this.conditions = inter;
	}

	public void setConditions(Node traitement) {
		NodeList conds = traitement.getChildNodes();
		setConditions(conds);
	}

	private Condition conditionNodeToObject(Node condition) {
		Node nom = condition.getChildNodes().item(0);
		Node operateur = condition.getChildNodes().item(1);
		Node valeur = condition.getChildNodes().item(2);
		Node reponse = condition.getChildNodes().item(3);

		return (new Condition(nom, operateur, valeur, reponse));
	}

}
